class Solution {
    public boolean isValidBST(TreeNode root) {
        return dfs(root)[0] != Long.MIN_VALUE;
    }
    public long[] dfs(TreeNode node){
        if(node == null){
            return new long[]{Long.MAX_VALUE,Long.MIN_VALUE};
        }
        long[] left = dfs(node.left);
        long[] right = dfs(node.right);
        long x = node.val;
        if(x >= right[0] || x <= left[1]){//x>右边最小值 || x<左边最大值
            return new long[]{Long.MIN_VALUE,Long.MAX_VALUE};
        }
        return new long[]{Math.min(left[0],x),Math.max(right[1],x)};
    }
}

/**
 class Solution {
 private long prev = Long.MIN_VALUE;
 public boolean isValidBST(TreeNode root) {
 if(root == null) return true;
 if(!isValidBST(root.left) || root.val <= prev){
 return false;
 }
 prev = root.val;
 return isValidBST(root.right);
 }
 } */
/**
 class Solution {
 public boolean isValidBST(TreeNode root) {
 return qian(root, Long.MIN_VALUE, Long.MAX_VALUE);
 }
 public boolean qian(TreeNode node, long left, long right){
 if(node == null){
 return true;
 }
 long x = node.val;
 return x > left && x < right && qian(node.left, left, x)
 && qian(node.right, x, right);
 }
 }
 */
public class Test {
}
class Solution {
    public int[] twoSum(int[] numbers, int target) {
        int l = 0;
        int r = numbers.length - 1;
        while(l <= r){
            while(l <= r && numbers[l] + numbers[r] > target){
                r--;
            }
            while(l <= r && numbers[l] + numbers[r] < target){
                l++;
            }
            if(numbers[l] + numbers[r] == target){
                return new int[]{l+1,r+1};
            }
        }
        return new int[]{0,0};
    }
}
